package cn.wh.beans.factory.support;

import cn.wh.BeansException;
import cn.wh.beans.factory.BeanFactory;
import cn.wh.beans.factory.support.config.BeanDefinition;

/**
 * @author: wh
 * @create: 2022-08-17 15:33
 * @description  注册bean 接口
 **/
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {

    @Override
    public Object getBean(String name) throws BeansException {
        Object bean = getSingleton(name);
        if (bean!=null){
            return bean;
        }
        BeanDefinition beanDefinition = getBeanDefinition(name);
        return createBean(name,beanDefinition);
    }

    protected abstract BeanDefinition getBeanDefinition(String beanName) throws BeansException;


    protected abstract Object createBean(String beanName,BeanDefinition beanDefinition) throws BeansException;


}
